package com.dayuanit.dy15.ebook.bookshop.util;

import java.math.BigDecimal;

public class MoneyUtil {

    public static String add(String amount, String otherAmount) {
        BigDecimal bigDecimal = new BigDecimal(amount);
        BigDecimal otherDecimal = new BigDecimal(otherAmount);
        return bigDecimal.add(otherDecimal).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
    }

    public static int add(String amount, int otherAmount) {
        BigDecimal bigDecimal = new BigDecimal(amount);
        BigDecimal otherDecimal = new BigDecimal(String.valueOf(otherAmount));
        return bigDecimal.multiply(new BigDecimal("100")).add(otherDecimal).intValue();
    }

    public static String mul(String num1, String num2) {
        BigDecimal bigDecimal = new BigDecimal(num1);
        BigDecimal otherDecimal = new BigDecimal(num2);
        return bigDecimal.multiply(otherDecimal).setScale(2, BigDecimal.ROUND_HALF_DOWN).toString();
    }

    public static void sub() {

    }

    public static int yuanTofen(String amount) {
        return new BigDecimal(amount).multiply(new BigDecimal("100")).intValue();
    }

    public static String fenToYuan(int amount) {
        return new BigDecimal(String.valueOf(amount)).divide(new BigDecimal("100"))
                .setScale(2, BigDecimal.ROUND_HALF_UP).toString();
    }

    public static void div() {

    }
}
